﻿; (function (window, undefined, $) {

    $(document).ready(function () {

        var gridopt = {
            url: options.listUrl,
            colModel: [
                    { display: '编号', name: 'ID', width: "3%", sortable: true, hide: true, align: 'left', iskey: true },
                    { display: '字典项名', name: 'Name', width: "10%", sortable: false, align: 'left' },
                    { display: '字典项编码', name: 'Code', width: "10%", sortable: false, align: 'left' },
                    //{ display: '电子邮件', name: 'Email', width: "10%", sortable: false, align: 'left' },
                    //{ display: '部门', name: 'DeptName', width: "10%", sortable: false, align: 'left' },
                    //{ display: '状态', name: 'IsStop', width: "10%", sortable: false, align: 'left', process: formatIsStop },
                    { display: '操作', name: 'ID', width: "10%", sortable: false, align: 'center', process: processOp }

            ],
            sortname: "Id",
            sortorder: "DESC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        function processOp(value, cell) {
            var ops = [];
            ops.push("&nbsp;<a title='编辑' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>编辑</a>");
            ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            return ops.join("");
        }

        function formatIsStop(value, cell)
        {
            if (value.toUpperCase()=="TRUE") {
                return "锁定";
            }
            else {
                return "正常";
            }
        }
        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });
        $("#btnAdd").click(function (e) {
            $.layer({
                type: 2,
                shade: [0.5, '#000'],
                fix: true,
                title: '编辑用户',
                maxmin: false,
                iframe: { src: options.editUrl + "?DictDirId=" + $("#DictDirId").val() },
                area: ['800px', '550px'],
                end: function (index) {
                    //var sss = document.getElementById("id").value;
                    xjgrid.Reload();
                }
            });
        });

        util.Edit = function (id) {
            $.layer({
                type: 2,
                shade: [0.5, '#000'],
                fix: true,
                title: '编辑用户',
                maxmin: false,
                iframe: { src: options.editUrl+"?id="+id },
                area: ['800px', '550px'],
                end: function (index) {
                    //var sss = document.getElementById("id").value;
                    xjgrid.Reload();
                }
            });
        };
        util.Delete = function (id, name) {
 
            layer.confirm("您确定要执行该操作吗？", function (index) {
                $.post(options.deleteUrl + "/" + id, { id: id },
                      function (res) {
                          if (res.Status > 0) {
                              layer.msg('操作成功！', 2, 9);
                              xjgrid.Reload();
                          }
                          else {
                              layer.msg('操作失败！' + res.Message, 2, 8);
                          }
                      },
                      "json"
                );
            });
        };
    });

})(window, undefined, jQuery);